package cn.livingCloud.service.impl.operation;

import cn.livingCloud.context.BeanProvider;
import cn.livingCloud.entity.core.CaseImage;
import cn.livingCloud.entity.core.JobInfo;
import cn.livingCloud.repository.CaseImageMapper;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.List;

/**
 * Created by 唐旭 on 2016/6/30.
 */
public class DownloadImageJob implements JobInfo {
    private static final String JOB_NAME = "DownloadImageJob";
    private static final String JOB_GROUP = "DownloadImageJobGroup";
    //每两分钟执行一次
    private static final String CRON_EXPRESSION = "* 0/2 * * * ?";

    private transient CaseImageMapper imageMapper = BeanProvider.getBean(CaseImageMapper.class);

    @Override
    public String getJobName() {
        return JOB_NAME;
    }

    @Override
    public String getJobGroup() {
        return JOB_GROUP;
    }

    @Override
    public String getCronExpression() {
        return CRON_EXPRESSION;
    }

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        List<CaseImage> imageList = imageMapper.findStartWithString("wxImage:");
        for (CaseImage caseImage : imageList) {
            new CaseImageDownloadHandler(caseImage).handler();
        }
    }
}
